
package hmvictor.jpql.types;

import java.util.Objects;
import javax.persistence.Parameter;
import javax.persistence.Query;

/**
 *
 * @author Victor
 */
public class ComposedType<T> extends  AbstractParameterType<T>{
    private final Class<Editor<T>> editorClass;

    public ComposedType(String name, Class<Editor<T>> editorClass) {
        super(name);
        this.editorClass = editorClass;
    }
    
    @Override
    public Editor<T> createEditor() {
        try {
            return editorClass.newInstance();
        } catch (InstantiationException | IllegalAccessException ex) {
            throw new IllegalStateException();
        }
    }

    @Override
    public void setParameter(Query query, Parameter parameter, T value) {
        query.setParameter(parameter, value);
    }

}
